<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>finndyAPI</title>
	<link href="http://cdn.bootcss.com/bootstrap/4.0.0-alpha.3/css/bootstrap.css" rel="stylesheet">
	<script src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>

</head>
<body>

	<div class="form-group">
    <label for="exampleInputPassword1">Token</label>
    <input type="txt" class="form-control" id="token" placeholder="token" name="token" value="finndyToken">
  	</div>

  	<div class="form-group">
    <label for="exampleInputPassword1">title</label>
    <input type="txt" class="form-control" id="title" placeholder="title" name="title">
  	</div>
  	<div class="form-group">
    <label for="exampleInputPassword1">detail</label>
    <input type="txt" class="form-control" id="detail" placeholder="detail" name="detail">
  	</div>
  	<div class="form-group">
    <label for="exampleInputPassword1">author</label>
    <input type="txt" class="form-control" id="author" placeholder="author" name="author">
  	</div>
  	<div class="form-group">
    <label for="exampleInputPassword1">time</label>
    <input type="txt" class="form-control" id="time" placeholder="time" name="time">
  	</div>

  	<select class="form-control" id="forums">
	  <option >默认模块</option>
	</select>
	<div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <div class="checkbox">
        <label>
          <input type="checkbox" value="1" id="audit" checked>需要审核
        </label>
      </div>
    </div>
  </div>
<div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
	 <button type="submit" class="btn btn-default" onclick="_submit()">Submit</button>
  </div>
 </div>
	<script>
	// test = true;

	// 	url = 'http://test.finndy.com/wordpress';

	// $(function(){
	// 	var token = $('#token').val();		
	// 	$.get(url+'/wp-admin/plugins.php?plugin=finndywp%2Finterface.php&type=forums&token='+token,function(res){
	// 		if (res) {
	// 			//console.log(res);
	// 			var str = '';
	// 			$.each(res,function(k,v){
	// 				str += '<option value="'+v.id+'">'+v.name+'</option>';
	// 			});
	// 			$('#forums').html(str);
	// 		}else{
	// 			alert('fail');
	// 		}
	// 	},'json');
	// });


	// function _submit(){
	// 	var token = $('#token').val();
	// 	var title = $('#title').val();
	// 	var detail = $('#detail').val();
	// 	var author = $('#author').val();
	// 	var time = $('#time').val();
	// 	var audit = $('#audit').is(':checked');
		
	// 	var forums = $('#forums').find("option:selected").val();
	// 	$.post(url+'/wp-admin/plugins.php?plugin=finndywp%2Finterface.php&type=postdata&token='+token,{token:token,question_title:title,question_detail:detail,question_author:author,question_publish_time:time,question_categories:forums},function(res){
	// 		if (res) {
	// 			console.log(res);
				
	// 		}else{
	// 			alert('fail');
	// 		}
	// 	},'json');
		
	// }

	url = 'http://test.finndy.com/phpwind/index.php?app=finndy&m=app&c=index&a=details';

	$(function(){
		var token = $('#token').val();		
		$.post(url,{token:token},function(res){
			if (res.status) {
				console.log(res);
				var str = '';
				$.each(res.data,function(k,v){
					str += '<option value="'+v.id+'">'+v.name+'</option>';
				});
				$('#forums').html(str);
			}else{
				alert('fail');
			}
		},'json');
	});

	function _submit(){
		var token = $('#token').val();
		var title = $('#title').val();
		var detail = $('#detail').val();
		var author = $('#author').val();
		var time = $('#time').val();
		var audit = $('#audit').is(':checked');
		var forums = $('#forums').find("option:selected").val();
		$.post('http://test.finndy.com/phpwind/index.php?app=finndy&m=app&c=index&a=post',{token:token,question_title:title,question_detail:detail,question_author:author,question_publish_time:time,default_forum:forums},function(res){
			if (res) {
				console.log(res);
				
			}else{
				alert('fail');
			}
		},'json');
	};





	</script>
</body>
</html>